package com.example.crawlerjava.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class CacheConfig {

    @Bean
    public CaffeineCacheManager cacheManager() {
        CaffeineCacheManager cacheManager = new CaffeineCacheManager();
        // 可以配置缓存的名称，如果不配置，则使用方法名作为缓存的键
        cacheManager.setCaffeine(Caffeine.newBuilder()
                .maximumSize(500) // 最大缓存条目数
                .expireAfterWrite(10, TimeUnit.MINUTES)); // 10分钟后过期
        return cacheManager;
    }
}
